import 'package:flutter/material.dart';
import 'package:fsharing/core/models/address.dart';
import 'package:fsharing/core/models/bank.dart';
import 'package:fsharing/core/models/business_level.dart';
import 'package:fsharing/core/models/business_type.dart';
import 'package:fsharing/core/models/me.dart';
import 'package:fsharing/core/models/order_detail.dart';
import 'package:fsharing/core/models/store_index.dart';
import 'package:fsharing/core/models/user_total.dart';
import 'package:fsharing/ui/pages/mine/order/logistics_page.dart';
import 'package:fsharing/ui/pages/cart/cart_page.dart';
import 'package:fsharing/ui/pages/cart/order_confirm_page.dart';
import 'package:fsharing/ui/pages/home/news_detail_page.dart';
import 'package:fsharing/ui/pages/home/news_page.dart';
import 'package:fsharing/ui/pages/main_page.dart';
import 'package:fsharing/ui/pages/mine/address/address_edit_page.dart';
import 'package:fsharing/ui/pages/mine/address/address_page.dart';
import 'package:fsharing/ui/pages/mine/address/address_region_page.dart';
import 'package:fsharing/ui/pages/mine/account_detail_page.dart';
import 'package:fsharing/ui/pages/mine/account_page.dart';
import 'package:fsharing/ui/pages/mine/forget_page.dart';
import 'package:fsharing/ui/pages/mine/manage/bank_edit_page.dart';
import 'package:fsharing/ui/pages/mine/manage/bank_page.dart';
import 'package:fsharing/ui/pages/mine/manage/bank_type_page.dart';
import 'package:fsharing/ui/pages/mine/manage/business_condition_page.dart';
import 'package:fsharing/ui/pages/mine/manage/business_level_page.dart';
import 'package:fsharing/ui/pages/mine/manage/business_type_page.dart';
import 'package:fsharing/ui/pages/mine/manage/store_manage_page.dart';
import 'package:fsharing/ui/pages/mine/order/order_detail_page.dart';
import 'package:fsharing/ui/pages/mine/order/order_page.dart';
import 'package:fsharing/ui/pages/mine/qrcode_page.dart';
import 'package:fsharing/ui/pages/mine/store_apply_page.dart';
import 'package:fsharing/ui/pages/mine/user_mobile_page.dart';
import 'package:fsharing/ui/pages/mine/user_nickname_page.dart';
import 'package:fsharing/ui/pages/mine/user_password_page.dart';
import 'package:fsharing/ui/pages/mine/user_renew_page.dart';
import 'package:fsharing/ui/pages/mine/webview_page.dart';
import 'package:fsharing/ui/pages/splash_page.dart';
import 'package:fsharing/ui/pages/store/product_page.dart';
import 'package:fsharing/ui/pages/home/search_page.dart';
import 'package:fsharing/ui/pages/mine/auth_page.dart';
import 'package:fsharing/ui/pages/mine/invite_page.dart';
import 'package:fsharing/ui/pages/mine/invited_page.dart';
import 'package:fsharing/ui/pages/mine/login_page.dart';
import 'package:fsharing/ui/pages/mine/register_page.dart';
import 'package:fsharing/ui/pages/mine/setting_page.dart';
import 'package:fsharing/ui/pages/mine/user_page.dart';
import 'package:fsharing/ui/pages/mine/manage/withdraw_account_page.dart';
import 'package:fsharing/ui/pages/mine/manage/withdraw_edit_page.dart';
import 'package:fsharing/ui/pages/mine/manage/withdraw_page.dart';
import 'package:fsharing/ui/pages/store/store_category_page.dart';
import 'package:fsharing/ui/pages/store/store_page.dart';

class Router {
  static Route<dynamic> generateRoute(RouteSettings settings) {
    debugPrint('Router ${settings.name} ${settings.arguments}');

    switch (settings.name) {
      case '/':
        return MaterialPageRoute(builder: (_) => SplashPage());

      case '/main':
        return MaterialPageRoute(builder: (_) => MainPage(), settings: settings);

      case '/setting':
        Me me = settings.arguments;
        return MaterialPageRoute(builder: (_) => SettingPage(me: me));

      case '/login':
        return MaterialPageRoute(builder: (_) => LoginPage());

      case '/register':
        return MaterialPageRoute(builder: (_) => RegisterPage());

      case '/product':
        ProductPageArgs args = settings.arguments;
        return MaterialPageRoute(builder: (_) => ProductPage(args: args));

      case '/order':
        OrderPageArgs args = settings.arguments;
        return MaterialPageRoute(builder: (_) => OrderPage(args: args));

      case '/order/confirm':
        Map<String, int> cartIdQuantity = settings.arguments;
        return MaterialPageRoute(builder: (_) => OrderConfirmPage(cartIdQuantity: cartIdQuantity));

      case '/order/detail':
        OrderDetailPageArgs args = settings.arguments;
        return MaterialPageRoute(builder: (_) => OrderDetailPage(args: args));

      case '/address':
        bool selectable = settings.arguments ?? false;
        return MaterialPageRoute(builder: (_) => AddressPage(selectable: selectable ?? false));

      case '/address/edit':
        Address address = settings.arguments;
        return MaterialPageRoute(builder: (_) => AddressEditPage(address: address));

      case '/address/region':
        AddressRegionArgs args = settings.arguments;
        return MaterialPageRoute(builder: (_) => AddressRegionPage(args: args));

      case '/user':
        Me me = settings.arguments;
        return MaterialPageRoute(builder: (_) => UserPage(me: me));

      case '/user/nickname':
        Me me = settings.arguments;
        return MaterialPageRoute(builder: (_) => UserNicknamePage(me: me));

      case '/user/mobile':
        Me me = settings.arguments;
        return MaterialPageRoute(builder: (_) => UserMobilePage(me: me));

      case '/user/password':
        return MaterialPageRoute(builder: (_) => UserPasswordPage());

      case '/store':
        StorePageArgs args = settings.arguments;
        return MaterialPageRoute(builder: (_) => StorePage(args: args));

      case '/store/category':
        int storeId = settings.arguments;
        return MaterialPageRoute(builder: (_) => StoreCategoryPage(storeId: storeId));

      case '/store/manage':
        int id = settings.arguments;
        return MaterialPageRoute(builder: (_) => StoreManagePage(storeId: id));

      case '/store/apply':
        UserTotal userTotal = settings.arguments;
        return MaterialPageRoute(builder: (_) => StoreApplyPage(userTotal: userTotal));

      case '/bank':
        bool selectable = settings.arguments ?? false;
        return MaterialPageRoute(builder: (_) => BankPage(selectable: selectable));

      case '/bank/edit':
        Bank bank = settings.arguments;
        return MaterialPageRoute(builder: (_) => BankEditPage(bank: bank));

      case '/bank/type':
        return MaterialPageRoute(builder: (_) => BankTypePage());

      case '/business/type':
        return MaterialPageRoute(builder: (_) => BusinessTypePage());

      case '/business/level':
        BusinessType businessType = settings.arguments;
        return MaterialPageRoute(builder: (_) => BusinessLevelPage(businessType: businessType));

      case '/business/condition':
        BusinessLevel businessLevel = settings.arguments;
        return MaterialPageRoute(
            builder: (_) => BusinessConditionPage(businessLevel: businessLevel));

      case '/withdraw':
        int storeId = settings.arguments;
        return MaterialPageRoute(builder: (_) => WithdrawPage(storeId: storeId));

      case '/withdraw/edit':
        return MaterialPageRoute(builder: (_) => WithdrawEditPage());

      case '/withdraw/account':
        return MaterialPageRoute(builder: (_) => WithdrawAccountPage());

      case '/account':
        String category = settings.arguments;
        return MaterialPageRoute(builder: (_) => AccountPage(category: category));

      case '/account/detail':
        int id = settings.arguments;
        return MaterialPageRoute(builder: (_) => AccountDetailPage(id: id));

      case '/search':
        return MaterialPageRoute(builder: (_) => SearchPage());

      case '/auth':
        Me me = settings.arguments;
        return MaterialPageRoute(builder: (_) => AuthPage(me: me));

      case '/invite':
        Me me = settings.arguments;
        return MaterialPageRoute(builder: (_) => InvitePage(me: me));

      case '/invited':
        InvitedPageArgs args = settings.arguments;
        return MaterialPageRoute(builder: (_) => InvitedPage(args: args));

      case '/renew':
        int userId = settings.arguments;
        return MaterialPageRoute(builder: (_) => UserRenewPage(userId: userId));

      case '/qrcode':
        return MaterialPageRoute(builder: (_) => QrcodePage());

      case '/forget':
        return MaterialPageRoute(builder: (_) => ForgetPage());

      case '/news':
        return MaterialPageRoute(builder: (_) => NewsPage());

      case '/news/detail':
        Link link = settings.arguments;
        return MaterialPageRoute(builder: (_) => NewsDetailPage(link: link));

      case '/cart':
        return MaterialPageRoute(builder: (_) => CartPage());

      case '/webview':
        WebViewPageArgs args = settings.arguments;
        return MaterialPageRoute(builder: (_) => WebViewPage(args: args));

      case '/logistics':
        Invoice invoice = settings.arguments;
        return MaterialPageRoute(builder: (_) => LogisticsPage(invoice: invoice));

      default:
        return MaterialPageRoute(
          builder: (context) => Scaffold(
            body: Center(
              child: Text('No route defined for ${settings.name}'),
            ),
          ),
        );
    }
  }
}
